﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.TypeParameterConstraint"/>.
    /// </summary>
    public abstract class TypeParameterConstraintVM : CodeObjectVM
    {
        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.TypeParameterConstraint"/>.
        /// </summary>
        protected TypeParameterConstraintVM(TypeParameterConstraint typeParameterConstraint, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(typeParameterConstraint, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.TypeParameterConstraint"/> model.
        /// </summary>
        public TypeParameterConstraint TypeParameterConstraint
        {
            get { return (TypeParameterConstraint)CodeObject; }
        }

        #endregion

        #region /* RENDERING */

        public override void Render(CodeRenderer renderer, RenderFlags flags)
        {
            if (flags.HasFlag(RenderFlags.PrefixSpace))
                renderer.RenderText(" ", PUNC_BRUSH, ParentVM);

            bool hasBorder = flags.HasFlag(RenderFlags.ForceBorder) && !flags.HasFlag(RenderFlags.NoBorder);
            if (hasBorder)
                CreateBorder(renderer, flags);

            RenderFlags passFlags = (flags & RenderFlags.PassMask);
            RenderBefore(renderer, passFlags | RenderFlags.IsPrefix);
            RenderConstraint(renderer, passFlags);
            RenderEOLComments(renderer, flags);
            RenderAfter(renderer, passFlags | (flags & RenderFlags.NoPostAnnotations));

            // If we have a border, return to the previous one
            if (hasBorder)
                renderer.ReturnToBorderParent(this);
        }

        protected virtual void RenderConstraint(CodeRenderer renderer, RenderFlags flags)
        {
            renderer.RenderText(TypeParameterConstraint.ConstraintText, KEYWORD_BRUSH, this);
        }

        #endregion
    }
}
